package com.lanou3g.code0523;

import com.sun.deploy.net.HttpRequest;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class FirstFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        //初始化方法,作用等同于  servlet的init方法

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        //每次执行过滤的时候 调用方法
        HttpServletRequest req= (HttpServletRequest) servletRequest;
        HttpServletResponse resp= (HttpServletResponse) servletResponse;
        HttpSession session =req.getSession();
        resp.setContentType("text/html;charset=utf-8");
        req.setCharacterEncoding("utf-8");
        filterChain.doFilter(servletRequest,servletResponse);//放行这次请求

    }

    @Override
    public void destroy() {
        //当 filter销毁的时候,会调用的方法
    }
}
